package 我的Java学习_算法基础.day_07;

import java.util.Scanner;

/**
 * @author 挚爱之夕
 * @date 2021/8/21 - 08 - 21 - 16:07
 * @Description: 我的暑假Java学习.day_07
 * @Version: 1.0
 */
public class _117_水洼数 {
    private static int m;   //行数
    private static int n;   //列数

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        m = sc.nextInt();
        n = sc.nextInt();
        char[][] a = new char[m][];
        for (int i = 0; i < m; i++) {
            a[i] = sc.next().toCharArray();
        }
        int count = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i][j] == 'w') {
                    dfs(a, i, j);//清除水洼
                    count++;
                }
            }
        }
        System.out.println(count);
    }

    private static void dfs(char[][] a, int i, int j) {
        a[i][j] = '.';
        //八个方位
        for (int k = -1; k < 2; k++) {//k正表示东，l正表示北,都负表示西北
            for (int l = -1; l < 2; l++) {
                if (k == 0 && l == 0) continue; //都正表示自身，跳过
                if (i + k >= 0 && i + k <= m - 1 && j + l >= 0 && j + l <= n - 1) {//防止越界
                    if (a[i + k][j + l] == 'w') {
                        dfs(a, i + k, j + l);
                    }
                }
            }
        }
    }

}
/*
w........ww.
.www.....www
....ww...ww.
.........ww.
.........w..
..w......w..
.w.w.....ww.
w.w.w.....w.
.w.w......w.
..w.......w.
输出3
 */
/*
w........ww.
.www.....www
....ww...ww.
.w.......ww.
.........w..
..w.........
.w.w.....ww.
w.w.w.....w.
.w.w......w.
..w.......w.
输出5
 */